﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Controls;

namespace TestRunner 
{
    [ValueConversion(typeof(bool), typeof(Visibility))]
    public sealed class RowDetailsVisiblityConverter : IValueConverter 
    {
        public DataGridRowDetailsVisibilityMode TrueValue { get; set; }
        public DataGridRowDetailsVisibilityMode FalseValue { get; set; }

        public RowDetailsVisiblityConverter() 
        {
            // set defaults
            TrueValue = DataGridRowDetailsVisibilityMode.VisibleWhenSelected;
            FalseValue = DataGridRowDetailsVisibilityMode.Collapsed;
        }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
        {
            if (!(value is bool))
                return null;
            return (bool)value ? TrueValue : FalseValue;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
        {
            if (Equals(value, TrueValue))
                return true;
            if (Equals(value, FalseValue))
                return false;
            return null;
        }
    }
}
